<?php
 
/**
* php 生成4位的随机数字验证码
* edit: www.jbxue.com
*/
$ttf = './wqy.ttf';
$num = $_GET['num'];
 
//生成验证码图片
Header("Content-type: image/PNG");
$im = imagecreate(200,200);
$red = ImageColorAllocate($im, 255,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
$black = ImageColorAllocate($im, 0,0,0);
 
 
imagefill($im, 1, 1, $white);
 
//将四位整数验证码绘入图片
//位置交错

if(strlen($num) == 1)
	imagettftext($im, 100, 0, 60, 150, $black, $ttf, $num);
else if(strlen($num) == 2)
	imagettftext($im, 100, 0, 20, 150, $black, $ttf, $num);
else if(strlen($num) == 3)
	imagettftext($im, 80, 0, 0, 140, $black, $ttf, $num);
 
ImagePNG($im);
ImageDestroy($im);
?>